/**
 * 
 */
package com.wistech.search.solr.parse;

import java.io.StringReader;

import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.DisMaxQParser;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

/**
 * @author Liuye
 * 
 */
public class IKDisMaxQParser extends DisMaxQParser {
	public IKDisMaxQParser(String qstr, SolrParams localParams,
			SolrParams params, SolrQueryRequest req) {
		super(qstr, localParams, params, req);
		if (null == this.qstr) {
			return;
		}

		StringBuilder norm = new StringBuilder();
		try {
			// 分词
			IKSegmenter analyzer = new IKSegmenter(new StringReader(this.qstr),
					true);
			Lexeme lexeme;
			lexeme = analyzer.next();
			while (lexeme != null) {
				norm.append(lexeme.getLexemeText()).append(" ");
				lexeme = analyzer.next();
			}
		} catch (Exception ex) {
		}
		if (norm.length() > 0)
			this.qstr = norm.toString();
	}

}
